import 'package:learning/bean/question_entity.dart';
import 'package:learning/generated/json/base/json_convert_content.dart';

QuestionEntity $QuestionEntityFromJson(Map<String, dynamic> json) {
  final QuestionEntity questionEntity = QuestionEntity();
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    questionEntity.total = total;
  }
  final int? branching = jsonConvert.convert<int>(json['branching']);
  if (branching != null) {
    questionEntity.branching = branching;
  }
  final List<QuestionList>? list = (json['list'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<QuestionList>(e) as QuestionList).toList();
  if (list != null) {
    questionEntity.list = list;
  }
  return questionEntity;
}

Map<String, dynamic> $QuestionEntityToJson(QuestionEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['total'] = entity.total;
  data['branching'] = entity.branching;
  data['list'] = entity.list.map((v) => v.toJson()).toList();
  return data;
}

extension QuestionEntityExtension on QuestionEntity {
  QuestionEntity copyWith({
    int? total,
    int? branching,
    List<QuestionList>? list,
  }) {
    return QuestionEntity()
      ..total = total ?? this.total
      ..branching = branching ?? this.branching
      ..list = list ?? this.list;
  }
}

QuestionList $QuestionListFromJson(Map<String, dynamic> json) {
  final QuestionList questionList = QuestionList();
  final int? subject = jsonConvert.convert<int>(json['subject']);
  if (subject != null) {
    questionList.subject = subject;
  }
  final int? languageId = jsonConvert.convert<int>(json['languageId']);
  if (languageId != null) {
    questionList.languageId = languageId;
  }
  final String? optionC = jsonConvert.convert<String>(json['optionC']);
  if (optionC != null) {
    questionList.optionC = optionC;
  }
  final String? optionD = jsonConvert.convert<String>(json['optionD']);
  if (optionD != null) {
    questionList.optionD = optionD;
  }
  final String? remark = jsonConvert.convert<String>(json['remark']);
  if (remark != null) {
    questionList.remark = remark;
  }
  final String? optionA = jsonConvert.convert<String>(json['optionA']);
  if (optionA != null) {
    questionList.optionA = optionA;
  }
  final int? sort = jsonConvert.convert<int>(json['sort']);
  if (sort != null) {
    questionList.sort = sort;
  }
  final String? optionB = jsonConvert.convert<String>(json['optionB']);
  if (optionB != null) {
    questionList.optionB = optionB;
  }
  final int? type = jsonConvert.convert<int>(json['type']);
  if (type != null) {
    questionList.type = type;
  }
  final String? content = jsonConvert.convert<String>(json['content']);
  if (content != null) {
    questionList.content = content;
  }
  final String? tags = jsonConvert.convert<String>(json['tags']);
  if (tags != null) {
    questionList.tags = tags;
  }
  final int? difficulty = jsonConvert.convert<int>(json['difficulty']);
  if (difficulty != null) {
    questionList.difficulty = difficulty;
  }
  final String? answer = jsonConvert.convert<String>(json['answer']);
  if (answer != null) {
    questionList.answer = answer;
  }
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    questionList.id = id;
  }
  return questionList;
}

Map<String, dynamic> $QuestionListToJson(QuestionList entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['subject'] = entity.subject;
  data['languageId'] = entity.languageId;
  data['optionC'] = entity.optionC;
  data['optionD'] = entity.optionD;
  data['remark'] = entity.remark;
  data['optionA'] = entity.optionA;
  data['sort'] = entity.sort;
  data['optionB'] = entity.optionB;
  data['type'] = entity.type;
  data['content'] = entity.content;
  data['tags'] = entity.tags;
  data['difficulty'] = entity.difficulty;
  data['answer'] = entity.answer;
  data['id'] = entity.id;
  return data;
}

extension QuestionListExtension on QuestionList {
  QuestionList copyWith({
    int? subject,
    int? languageId,
    String? optionC,
    String? optionD,
    String? remark,
    String? optionA,
    int? sort,
    String? optionB,
    int? type,
    String? content,
    String? tags,
    int? difficulty,
    String? answer,
    int? id,
  }) {
    return QuestionList()
      ..subject = subject ?? this.subject
      ..languageId = languageId ?? this.languageId
      ..optionC = optionC ?? this.optionC
      ..optionD = optionD ?? this.optionD
      ..remark = remark ?? this.remark
      ..optionA = optionA ?? this.optionA
      ..sort = sort ?? this.sort
      ..optionB = optionB ?? this.optionB
      ..type = type ?? this.type
      ..content = content ?? this.content
      ..tags = tags ?? this.tags
      ..difficulty = difficulty ?? this.difficulty
      ..answer = answer ?? this.answer
      ..id = id ?? this.id;
  }
}